/**
 * 
 */
requirejs.config({
    baseUrl:'http://static.auoffice.com/static/js' ,
    waitSeconds: 0,
    paths: {
    	jquery:'libs/jquery.min',
    	validate:'libs/validate/jquery.validate.min',
        //plugins
        base: 'common/base',
    },
    shim: {
    	'validate': {
    		deps: ['jquery'],
    		exports: 'validate'
    	},
    }
});

require([
    'jquery',
 	'common/base',
 	'validate',
],function($,base) {
	$(document).ready(function(){
		var article_id = $("#article_id").val();
		//内容
		base.services.post('article', 'getContent', {"article_id":article_id}, function(code, msg, data) {
			if (code === base.services.CODE_SUCC) {
				$(".social-body").prepend(data.article_content);
				//评论
				base.services.post('comment', 'getCommentsByObj', {"app_label":"article","model":"Article","obj_id":article_id}, function(code, msg, data) {
					if (code === base.services.CODE_SUCC) {
						var html = "";
						for (var comment in data.comments){
							var children_html = "";
							for (var children in data.comments[comment].childrens){
								children_html += '<div class="social-comment">';
								children_html += '<div class="media-body">';
								children_html += '<a href="#">'+data.comments[comment].childrens[children].first_name+'</a>&nbsp;回复&nbsp;<a href="#">'+data.comments[comment].childrens[children].from_first_name+'</a>'; 
								children_html += '<br>'+data.comments[comment].childrens[children].content+'<br><small class="text-muted pull-right">'+data.comments[comment].childrens[children].create_time+'</small></div></div>';
							}
							html += '<div class="social-comment">';
							html += '<a href="#" class="pull-left">';
							html += '<img alt="image" src="'+data.comments[comment].avatar_url+'"></a>';
							html += '<div class="media-body">';
							html += '<a href="#">'+data.comments[comment].first_name+': </a>'+data.comments[comment].content;
							html += '<br/><small class="text-muted pull-right">'+data.comments[comment].create_time+'</small></div>'+children_html+'</div>';
						}
						$(".social-footer").append(html);
					}
				});
			}
		});
	});
});